package odgs.pda.sender;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;

import odgs.ExplorerNode;
import odgs.GridNode;
import odgs.GridState;
import odgs.message.Message;

public class LoginResponseSender implements SendMessageHandler{
	public LoginResponseSender() {
	}

	public void send(Message msg, OutputStream os) {
		System.out.println(msg.getName() + "  sended");
		ByteArrayOutputStream bout = new ByteArrayOutputStream();
		
		GridState state = (GridState) msg.get("state");
		List<ExplorerNode> data = (List<ExplorerNode>) msg.get("explorer");
		
		String strData = "LoginResponse\n";
		
		for(int i = 0; i < data.size(); i++){
			strData += data.get(i).getPath();
			strData += data.get(i).toString() + "\n";
		}
		
		strData += "|";
		
		try {
			bout.write(strData.getBytes());
			os.write(bout.toByteArray());
			os.flush();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
